// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
// SPDX-License-Identifier: MIT

import { env } from "~/env";
/**
 * 解析服务URL
 * @param path - API路径
 * @returns 完整的服务URL字符串
 * 
 * 功能说明:
 * 1. 获取环境变量中配置的API基础URL,默认为localhost:8000
 * 2. 确保基础URL以/结尾
 * 3. 将传入的path与基础URL拼接成完整URL
 */


export function resolveServiceURL(path: string) {
  let BASE_URL = env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000/api/";
  if (!BASE_URL.endsWith("/")) {
    BASE_URL += "/";
  }
  return new URL(path, BASE_URL).toString();
}
